<template>
	<view class="">
		<page-head title="退款" :headtype="2"></page-head>
		<view class="content">
			<view class="product_warp">
				<view v-for="(item,index) in orderDetail.detail" :key="index" style="width: 100%;"
					:class="index!=0?'marT20':''">
					<product-item-num :item="item" type="end"></product-item-num>
				</view>
			</view>
			<view class="modal">
				<view class="title">
					选择退款原因
				</view>
				<view class="m_body">
					<view class="mb_item" @click.stop="selType=1">
						<text style="color: #666666;font-size: 28rpx;">尺寸不符</text>
						<u-icon name="checkmark-circle-fill" :size="36" color="#DFDFDF" v-if="selType!=1"></u-icon>
						<u-icon name="checkmark-circle-fill" :size="36" color="#D31E11" v-if="selType==1"></u-icon>
					</view>
					<view class="mb_item" @click.stop="selType=2">
						<text style="color: #666666;font-size: 28rpx;">商品瑕疵</text>
						<u-icon name="checkmark-circle-fill" :size="36" color="#DFDFDF" v-if="selType!=2"></u-icon>
						<u-icon name="checkmark-circle-fill" :size="36" color="#D31E11" v-if="selType==2"></u-icon>
					</view>
					<view class="mb_item" @click.stop="selType=3">
						<text style="color: #666666;font-size: 28rpx;">质量问题</text>
						<u-icon name="checkmark-circle-fill" :size="36" color="#DFDFDF" v-if="selType!=3"></u-icon>
						<u-icon name="checkmark-circle-fill" :size="36" color="#D31E11" v-if="selType==3"></u-icon>
					</view>
					<view class="mb_item" @click.stop="selType=4">
						<text style="color: #666666;font-size: 28rpx;">其他</text>
						<u-icon name="checkmark-circle-fill" :size="36" color="#DFDFDF" v-if="selType!=4"></u-icon>
						<u-icon name="checkmark-circle-fill" :size="36" color="#D31E11" v-if="selType==4"></u-icon>
					</view>
				</view>
			</view>
			<view class="remark_warp" v-if="selType==4">
				<textarea v-model="value1" class="remark_inner" placeholder="请输入其他原因"></textarea>
			</view>
			<view :class="issub?'submit':'nosubmit'" @click="issub?submit():''">
				提交
			</view>
			<view style="font-size: 24rpx;color: #9E9E9E;text-align: center;margin-top: 26rpx;">
				平台同意后退货即可寄回商品
			</view>
		</view>
	</view>
</template>

<script>
	import productItemNum from "@/components/product_item_num.vue"
	import orderCell from "@/components/order_cell.vue"
	export default {
		components: {
			productItemNum,
			orderCell
		},
		data() {
			return {
				order_sn: null,
				orderDetail: {},
				selType: null,
				value1: "",
				issub: true
			}
		},
		onLoad(options) {
			if (options.orderSn) {
				this.order_sn = options.orderSn
				this.getOrderDetail()
			}
		},
		methods: {
			submit() {
				if (this.selType > 0) {
					if (this.selType == 4) {
						if (this.value1 == "") {
							this.apifun.toast("请填写其他原因")
							return false;
						}
					}
					let data = {
						order_sn: this.orderDetail.order_sn,
						type: this.selType
					}
					if (this.selType == 4) {
						data.refund_reason = this.value1
					}
					this.issub = false
					this.apifun.unirequest("/api/order/addRefund", "post", data, (res => {
						if (res.code == 200) {
							this.apifun.toast("已申请")
							
									let pages = getCurrentPages();
									let prevPage = pages[pages.length - 2];
									prevPage.$vm.page = 1
									prevPage.$vm.orderList = []
									prevPage.$vm.nodata = true
									prevPage.$vm.more = true
									prevPage.$vm.getOrderList()
									uni.navigateBack({
										delta: 1
									})
						} else {
							this.issub = true
							this.apifun.toast(res.msg)
						}
					}), true, true)
				}else{
					this.apifun.toast("请选择原因")
				}
			},
			async getOrderDetail() {
				let data = {
					order_sn: this.order_sn
				}
				await this.apifun.unirequest('/api/order/getOrderDetail', 'post', data, (res => {
					if (res.code == 200) {
						this.orderDetail = res.data
					} else {
						this.apifun.toast(res.msg)
					}
				}), true, true)
			},
		}
	}
</script>

<style lang="scss" scoped>
	.nosubmit {
		width: 600rpx;
		height: 88rpx;
		border-radius: 10rpx;
		background-color: #9e8786;
		display: flex;
		justify-content: center;
		align-items: center;
		color: #FFFFFF;
		font-size: 30rpx;
		margin: 0rpx auto;
		margin-top: 100rpx;
	}

	.submit {
		width: 600rpx;
		height: 88rpx;
		border-radius: 10rpx;
		background-color: #9E190F;
		display: flex;
		justify-content: center;
		align-items: center;
		color: #FFFFFF;
		font-size: 30rpx;
		margin: 0rpx auto;
		margin-top: 100rpx;
	}

	.remark_warp {
		width: 690rpx;
		height: 400rpx;
		border-radius: 20rpx;
		background-color: #FFFFFF;
		margin-top: 20rpx;
		padding: 30rpx;
		box-sizing: border-box;
	}

	.mb_item {
		display: flex;
		align-items: center;
		justify-content: space-between;
		width: 100%;
		height: 80rpx;
	}

	.title {
		font-size: 28rpx;
		color: #333333;
		font-weight: bold;
	}

	.modal {
		margin-top: 38rpx;
	}

	.m_body {
		width: 690rpx;
		border-radius: 20rpx;
		padding: 20rpx 40rpx 20rpx 30rpx;
		background-color: #FFFFFF;
		margin-top: 10rpx;
		box-sizing: border-box;
	}

	.marT20 {
		margin-top: 20rpx;
	}

	.product_warp {
		width: 690rpx;
		border-radius: 20rpx;
		background-color: #FFFFFF;
		padding: 24rpx;
		box-sizing: border-box;
		display: flex;
		flex-direction: column;
		margin: 0rpx auto;
	}

	.content {
		width: 100%;
		padding: 30rpx;
		box-sizing: border-box;
	}
</style>